package com.atguigu.admin.exception;

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * ClassName: CustomerHandlerExceptionResolver
 * Package: com.atguigu.admin.exception
 * Description:
 *
 * @Author Root
 * @Create 2023/4/24 11:39
 * @Version 1.0
 */
@Order(value = 0)
@Component
public class CustomerHandlerExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        try {
            response.sendError(511,"自定义错误");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return new ModelAndView();
    }
}
